# import pandas as pd
#
# # 使用pandas的read_json()方法读取JSON文件
# df = pd.read_json('D:\\temp\\test\\praise.json')
# ids = df['_id']
# # 打印DataFrame对象
# # while 1:
# for id in ids:
#     print(df['_type'])

# 提取特定列的值  
# mapping = df['mapping']
#
# print(mapping)
import json
# df = open('D:\\temp\\test\\praise.json')
# json_data = json.dump(df)
# parsed_data = json.load(json_data)
#
# for _source in parsed_data["id"]:
#     print("userName:",_source["userName"])

file1_path="D:\\temp\\test\\praise.json"
# file1=open(file1_path,encoding="UTF-8",mode="r").readlines()
# file1=open(file1_path,encoding="UTF-8",mode="r")

with open(file1_path, 'r', encoding='utf-8') as file1:
    with open("D:\\temp\\test\\praise_test.json", 'w',encoding='utf-8') as f:

        for id in file1.readlines():
            data = json.loads(id)
            f.write((str(data["_source"])).replace("'",'"')+"\n")
            # json_data = data["_source"]
            # json_data = [json.dumps(d, ensure_ascii=False) for d in data["_source"]]
            # 打开文件并将每个字典字符串写入文件的一行
            # with open("D:\\temp\\test\\praise_test.json", "w") as file:
            # f.write('\n'.join(json_data))

    # print(data['_source']['id'])

        # print(data['_source'])
        #     json.dump(data['_source'],f)
        #     json.dump(data['_source'],f,indent=1)



# 打开JSON文件
# with open('D:\\temp\\test\\praise.json', encoding = 'utf-8') as json_file:
#     data = json_file.readline()
    # data = json.load(json_file)
# ids = data['id']
# 提取name键的值
# for id in ids:
    # name = data['_type']

# 打印结果
#     print(data['_type'])
# list = [x['_source'] for x in data]
# print(list)

